<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <base href="<%=basePath%>">
  <title>jsapi</title>
  <script src="wxpay/jquery-1.8.2.min.js" type="text/javascript"></script>
 <style>
	.choose{width:500px;height:300px;margin:0 auto;background:#FCF;margin-top:150px;text-align:center;padding-top:100px;}
  </style>
 </head>

 <body>
 	输入openid:
	<input type="text" id="openid" value="oc802wzy3OL95PRVYwLGP1NVXy9U"/>
	<button class="choose" >
		Click me to pay!
	</button>
<%-- <input type="hidden" id="appId" value="${sendMap.appId}"/>
<input type="hidden" id="timeStamp" value="${sendMap.timeStamp}"/>
<input type="hidden" id="nonceStr" value="${sendMap.nonceStr}"/>
<input type="hidden" id="package" value="${sendMap["package"]}"/>
<input type="hidden" id="signType" value="${sendMap.signType}"/>
<input type="hidden" id="paySign" value="${sendMap.paySign}"/>
 --%>
 </body>

 <script>
 var xmlHttpRequest;

 $(function(){
	 if(window.XMLHttpRequest){
		 	xmlHttpRequest=new XMLHttpRequest();
	 }else{
	 		xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
	 }
	 xmlHttpRequest.open("GET","AjaxServlet",true);

 });
 //var packageParam={"appId":"wxd575cf1c4ffbfa13","nonceStr":"1747553870","package":"prepay_id=wx20160727174755c76e8f779b0867783686","paySign":"FE84C99764BE74AE42E0473FC61223F1","signType":"MD5","timeStamp":"1469612875"};
 var packageParam={};
 var openid=$("#openid").val();
 var data={"platform_type":"test002","body":"商品信息","orderId":new Date().getTime(),"total_fee":"0.01","openId":openid};
 	$(document).ready( function(){
 	 $.ajax({
 				type:"GET",
 				url:"wxpay/getPackage",
 				dataType:"json",
 				data:data,
 				async:false,
 				success:function(data){
 					//alert(JSON.stringify(data));
 					packageParam=data;
 				},
 				error:function(data){
 					//alert(JSON.stringify(data));
 				}
 		})
		$(".choose").click(function(){
			 WeixinJSBridge.invoke('getBrandWCPayRequest', {
			      "appId" : packageParam.appId,
						"timeStamp" : packageParam.timeStamp, 
						"nonceStr" :packageParam. nonceStr,
						"package" : packageParam['package'],
						"signType" : packageParam.signType,
						"paySign" : packageParam.paySign 
			         },function (res) {
				         if (res.err_msg == 'get_brand_wcpay_request:ok'){
										alert("支付成功！");
				         }else{
										alert("抱歉，支付失败，请您重新尝试！");
										alert(JSON.stringify(res));
				         };
				     });
			
			
			
			
			 	/*  var appId = $("#appId").val();
		     var timeStamp = $("#timeStamp").val();
		     var nonceStr = $("#nonceStr").val();
		     var package1 = $("#package").val();
		     var signType = $("#signType").val();
		     var paySign = $("#paySign").val();
	     WeixinJSBridge.invoke('getBrandWCPayRequest', {
	      "appId" : appId,
				"timeStamp" : timeStamp, 
				"nonceStr" : nonceStr,
				"package" : package1,
				"signType" : signType,
				"paySign" : paySign 
	         },function (res) {
		         if (res.err_msg == 'get_brand_wcpay_request:ok'){
								alert("支付成功！");
		         }else{
								alert("抱歉，支付失败，请您重新尝试！");
		         };
		     }); */
	    });
  });
 </script>
</html>
